<?php
namespace app\action\admin;
use core\BaseAction;
use core\App;
use core\JsonInfo;
use core\ParamFilter;
use app\model\User;
//标签管理
class LabelAction extends BaseAction{
	//加载标签列表页面
	function getList($params,$req,$res){
		return $this->view("admin.label_list");
	}
	//加载标签列表数据
	function postList($params){
		//调用业务逻辑
		$service = App::bean('\\app\\service\\admin\\LabelService');
		
		$u = User::$tableName;
		$m = $service->model();
		//初始化查询过滤器
		if($params['sort']=='create_time') $params['sort'] = $m.'.create_time';
		if($params['sort']=='name') $params['sort'] = $m.'.name';
		$filter = new ParamFilter($params);
	
		$table = $service->table()
			->join($u,"$m.user_id","=","$u.id")
			->select("$m.*","$u.login_name");
		$service->queryByFilter($filter,$table);
		
		$this->json($filter->grid);
	}
	
	//保存修改
	function postAdd($params){
		$info = new JsonInfo();
		if(empty($params['name'])){
			$info->msg = "非法数据";
		}else{
			$service = App::bean('\\app\\service\\admin\\LabelService');
			$service->saveLabel($params,$info);
		}
		return $this->json($info);
	}
	//删除标签
	function postDelete($params){
		$info = new JsonInfo();
		if(empty($params['Q_id_in'])){
			$info->msg = "非法数据";
		}else{
			$service = App::bean('\\app\\service\\admin\\LabelService');
			$service->deleteById($params['Q_id_in'],$info);
		}
		return $this->json($info);
	}
	//获取一篇文章中的标签数据
	function postArts($params){
		$info = new JsonInfo();
		if(empty($params['article_id'])){
			$info->msg = "非法数据";
		}else{
			$service = App::bean('\\app\\service\\admin\\LabelService');
			$list = $service->getLabelsByArticleId($params['article_id']);
			$info->success= true;
			$info->data = $list;
		}
		return $this->json($info);
	}
}